<?php
    
   $now_time=time();
   $end_time=strtotime("2015-09-28 00:00");
   if($now_time>$end_time)
   {
        echo '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>中秋活动已结束</title>
        </head>

        <body>
        抱歉，游戏不能玩了。活动已终止，活动截止时间：2015-09-27
        </body>
        </html>

        ';
        exit;
   }

    ini_set('session.gc_maxlifetime', 3*3600); //设置时间 
    session_start();
    require_once("../includes/conn.php");
    require_once "../includes/wxtoken.php";
    


    $sysconfig=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."_sys_config where uid=1"));


    define('APPID',$sysconfig['cappid']);
    define('APPSECRET',$sysconfig['cappsecret']);
    $tools=new tools();
    if(!$tools->check_is_weixin())
    {
        echo '
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>入口不合法</title>
        </head>

        <body>
         错误：必须在微信环境下进入。
        </body>
        </html>
        ';
        exit;
    }
    
    $wxtoken = new wxtoken(1);

    $signPackage = $wxtoken->GetSignPackage();

    $ucode= $_SESSION['ucode']?$_SESSION['ucode']:'';
    if(isset($_GET['code']) &&$_GET['code']!=''&&$ucode=='')
    {
        $WXCODE=$_GET['code'];
        $getucodeurl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$WXCODE."&grant_type=authorization_code";
        $getucodejson=json_decode($tools->http_curl_get($getucodeurl,true));
        $wxlintoken=$getucodejson->access_token;
        $ucode=$getucodejson->openid;
        $getutxturl="https://api.weixin.qq.com/sns/userinfo?access_token=".$wxlintoken."&openid=".$ucode."&lang=zh_CN";
        $getutxtjson =json_decode($tools->http_curl_get($getutxturl,true));
        $uickname    =$getutxtjson->nickname;
        $usex        =intval($getutxtjson->sex);
        $headimgurl  =$getutxtjson->headimgurl;
        $nums=$dbconn->countn(DBQIAN."_user_list"," ucode='$ucode' and uid=1 ");
        if($nums==0){
    		$times=time();
    		$dbconn->noretquery("insert into ".DBQIAN."_user_list(ucode,uickname,usex,uheadimgurl,utime,uid)values
    				 ('$ucode','$uickname',$usex,'$headimgurl',$times,1)");
        }

   }    
    elseif($ucode=='')
    {
        header("Location:index.php");exit();

    }    
    $_SESSION['ucode']=$ucode;
    // header("Location:mindex.html");exit;

    echo '
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,maximum-scale=1.0,user-scalable=no"/>
    <title>接月饼</title>
    <style>
    </style>
     <script src="lib/jquery-1.11.0.min.js"></script>
    <script src="lib/easeljs-0.7.1.min.js"></script>
    <script src="lib/tweenjs-0.5.1.min.js"></script>
    <script src="lib/preloadjs-0.4.1.min.js"></script>
    <script src="lib/movieclip-0.7.1.min.js"></script>
    <script src="lib/soundjs-0.5.2.min.js"></script>
    <script src="lib/common.js"></script>
    <script src="lib/app.js"></script>
    <script src="lib/loadingContent.js"></script>
    <script src="lib/loading.js"></script>
    <script src="lib/main.js"></script>

    <script>
	var _hmt = _hmt || [];
	(function() {
	  var hm = document.createElement("script");
	  hm.src = "//hm.baidu.com/hm.js?1a24dcebcea46c38830edf665b5d00e7";
	  var s = document.getElementsByTagName("script")[0];
	  s.parentNode.insertBefore(hm, s);
	})();

        var canvasLoading,canvas,stage,loadingStage,exportRoot;
        var queue=new createjs.LoadQueue();
        var score=0;
        var scale=1;
        var picNum=0;
        var picTotal=0;
        var loadingProgress=0;

        init();
        //initLoading();

        function init()
        {
            SHARE_ICON_URL="http://tgideas.qq.com/flash/quanchenTest/html5MidAutumn/images/icon.jpg";
            SHARE_URL="http://tgideas.qq.com/flash/quanchenTest/html5MidAutumn/index.html";
            SHARE_STR="你收到一份来自月球的思念和祝福!快快点击体验吧！";
            // onBridgeInit();
            initSound("sound/po","sound0");
            initSound("sound/po1","sound1");
            initSound("sound/po2","sound2");
        }

        function initLoading()
        {
            canvasLoading=document.getElementById("canvasLoading");

            loadingImages = loadingImages||{};

            var loader = new createjs.LoadQueue(false);
            loader.addEventListener("fileload", loadingHandleFileLoad);
            loader.addEventListener("complete", loadingHandleComplete);
            loader.loadManifest(loadingLib.properties.manifest);
        }

        function loadingHandleFileLoad(evt) {
            if (evt.item.type == "image") { loadingImages[evt.item.id] = evt.result; }
        }

        function loadingHandleComplete() {
            exportRoot = new loadingLib.loading();

            stage = new createjs.Stage(canvasLoading);
            stage.addChild(exportRoot);
            stage.update();

            createjs.Ticker.setFPS(loadingLib.properties.fps);
            createjs.Ticker.addEventListener("tick", stage);

            //console.log("loadingHandleComplete");

            //var loading=new lib.LOADING();
            //stage.addChild(loading);
            new loadingContent.init();
            initMain();
        }

        //
        function initMain()
        {
            canvas = document.getElementById("canvas");
            images = images||{};

            picTotal=lib.properties.manifest.length;

            var loader = new createjs.LoadQueue(false);
            loader.addEventListener("fileload", initHandleFileLoad);
            loader.addEventListener("complete", initHandleComplete);
            loader.loadManifest(lib.properties.manifest);
            console.log("initMain");
        }

        function initHandleFileLoad(evt) {
            picNum+=1;
            loadingProgress=picNum/picTotal;
            //console.log(loadingProgress);
            if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
        }

        function initHandleComplete() {
            //console.log("handleCompleteInit");
            document.getElementById("loading").style.display="none";
            exportRoot = new lib.main();

            stage = new createjs.Stage(canvas);
            stage.addChild(exportRoot);
            stage.update();

            createjs.Ticker.setFPS(lib.properties.fps);
            createjs.Ticker.addEventListener("tick", stage);

            new app.init();
        }

        function initSound(url,name)
        {
            var mp3url="";
            if(isAndroid())
            {
                createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
                mp3url=url+".ogg";
            }
            if(!isAndroid())
            {
                createjs.Sound.registerPlugins([createjs.WebAudioPlugin]);
                mp3url=url+".m4a";
            }
            createjs.Sound.alternateExtensions = ["mp3"];
            createjs.Sound.addEventListener("fileload", createjs.proxy(this.loadHandler, this));
            createjs.Sound.registerSound(mp3url, name);
        }

        function playSound0()
        {
            var instance = createjs.Sound.play("sound0");
            instance.volume = 0.5;
        }

        function playSound1()
        {
            var instance = createjs.Sound.play("sound1");
            instance.volume = 0.5;
        }

        function playSound2()
        {
            var instance = createjs.Sound.play("sound2");
            instance.volume = 0.5;
        }

        function loadHandler(event) {
            // This is fired for each sound that is registered.
            //var instance = createjs.Sound.play("sound");  // play using id.  Could also use full sourcepath or event.src.
            //instance.addEventListener("complete", createjs.proxy(this.soundComplete, this));
            //instance.volume = 0.5;
        }
    </script>
</head>
<body onload="initLoading();" style="background-color: #ffffff">
    <div id="loading" class="div-loading">
        <canvas id="canvasLoading" width="640" height="1008">
            sorry,your browser dosent support html5
        </canvas>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #a{
                display: block;
                background-color: gray;
            }
        </style>
    </div>
    <div id="main" class="div-main">
        <canvas id="canvas" width="640" height="1008">
            sorry,your browser dosenot support html5
        </canvas>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #a{
                display: block;
                background-color: gray;
            }
        </style>
    </div>
</body>
</html><!--[if !IE]>|xGv00|a6d03ba51a4aabe3b4e4bbfbc2d8709c<![endif]-->

    ';

	
?>